package com.itheima.mapper;

import com.itheima.entity.Dept;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.List;

@Mapper
public interface DeptMapper {

/*
   //方式一：创建一个ResultMap，映射数据库表和实体类对象的关系
    @Results(id = "deptMap", value = {
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "updateTime", column = "update_time")
    })
    */
/*
    //方式二：使用注解的方式，映射数据库表和实体类对象关系
    @Select("select id, name, create_time createTime, update_time updateTime from dept")
    */

    //方式三：全局配置，开启驼峰命名规则映射

    @Select("select * from dept")
    public List<Dept> list();

    @Delete("delete from dept where id=#{id}")
    void delete(Integer id);

    @Insert("insert into dept(name, create_time, update_time) values(#{name}, #{createTime}, #{updateTime})")
    void insert(Dept dept);

    @Select("select * from dept where id = #{id}")
    Dept getById(Integer id);

    @Update("update dept set name = #{name}, update_time = #{updateTime} where id = #{id}")
    void update(Dept dept);
}
